package pers.hxy.lookweather.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Shared Preferences Helper
 */
public class SpUtil {
    private static final String SP_FILE_NAME = "lookweather_sp";

    public static String getString(Context context, String key, String defaultValue) {
        return getSP(context).getString(key, defaultValue);
    }

    /** 默认返回null */
    public static String getString(Context context, String key) {
        return getString(context, key, null);
    }

    public static boolean putString(Context context, String key, String value) {
        SharedPreferences.Editor editor = getEditor(context);
        editor.putString(key, value);
        return editor.commit();
    }

    private static SharedPreferences getSP(Context context) {
        return context.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE);
    }

    private static SharedPreferences.Editor getEditor(Context context) {
        return getSP(context).edit();
    }
}
